<?php

namespace App\Http\Controllers\Main;

use App\CrmProduct;
use App\CrmProductCategory;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\CrmCase;

class ServiceController extends Controller
{
    public function service()
    {
        #获取一级分类
        $categoryOne = CrmProductCategory::where('level',1)->get();
        #获取二级分类
        $categoryTwo = array();
        $service = array();
        $product = array();
        foreach ($categoryOne as $k=>$v){
            $categoryTwo[$k] = CrmProductCategory::where('parent_id',$v->id)->orderBy('rank','desc')->take(6)->get();
//            #获取服务项
//            foreach ($categoryTwo[$k] as $key=>$value){
//                $service[$k][$key] = CrmProduct::where('category',$value->id)->orderBy('rank','desc')->get()->toArray();
//            }
            foreach ($categoryTwo[$k] as $t =>$o ) {
                $product[$o->id] = CrmCase::where('category',$o['id'])->get();
            }
        }

        $productCate = $this->productCate();
//        foreach ($categoryTwo[1] as $t =>$o ) {
////            $product[$t] = CrmCase::where('category',$o['id'])->get();
//            $product = $o;
//        }
//        dump($categoryOne);
//        dump($categoryTwo);
//        dump($product);
        $color = 3;
        return view('main/service',compact('categoryOne','categoryTwo','color','product','productCate'));
    }
}
